<%@page import="java.util.Calendar"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%
    request.setCharacterEncoding("utf-8");
    
    Calendar now = Calendar.getInstance();
    int year = now.get(Calendar.YEAR);
    int month = now.get(Calendar.MONTH)+1;
    
    String _year = request.getParameter("year");
    String _month = request.getParameter("month");
    
    if(_year != null)
        year = Integer.parseInt(_year);
    
    if(_month != null)
        month = Integer.parseInt(_month);
    
    now.set(year, month-1, 1);    //출력할 년도, 월로 설정
    
    year = now.get(Calendar.YEAR);    //변화된 년, 월
    month = now.get(Calendar.MONTH) + 1;
    
    int end = now.getActualMaximum(Calendar.DAY_OF_MONTH);    //해당월의 마지막 날짜
    int w = now.get(Calendar.DAY_OF_WEEK);    //1~7(일~토)
    
    %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<table width="200" border="1" align="right">
  <tr>
    <td bgcolor="#00FFFF">홈으로</td>
    <td>주단위</td>
    <td>월단위</td>
  </tr>
</table>
<br /><br /><br /><br />
<!--달력부분 !-->
<a href="month.jsp?year=<%=year%>&month=<%=month-1%>">◀</a>
                        <b><%=year %>年 <%=month %>月</b>
<a href="month.jsp?year=<%=year%>&month=<%=month+1%>">▶</a>
<br><br><br>
 
<th scope="col">
    <select> 
    <option>가나다라순</option>
    <option>근무시간순</option>
    <option>지각순</option>
    <option>출근시간순</option>
    </select>  
    </th>
<%
                   int newLine = 0;
                    //1일이 어느 요일에서 시작하느냐에 따른 빈칸 삽입
                    
                    for(int i=1; i<w; i++)
                    {
                        out.println("<td bgcolor='#ffffff'></td>");
                        newLine++;
                    }
                    
                    String fc, bg;
                    for(int i=1; i<=end; i++)
                    {
                        
                    	fc = (newLine == 0)?"red":(newLine==6?"blue":"#000000");
                        bg = "#ffffff";
                        out.println("<td align='center' bgcolor=" + bg + "><font color=" + fc + ">"
                                + i + "</font></td>");
                        newLine++;
                        if(newLine == 7 && i != end)
                        {
                            out.println("</tr>");
                            out.println("<tr height='25'>");
                            newLine = 0;
                        }
                    }
                    
                    while(newLine>0 && newLine<7)
                    {
                        out.println("<td bgcolor='ffffff'>&nbsp;</td>");
                        newLine++;    
                    }
                    out.println("</tr>");
                %>



</body>
</html>